package com.hualan.sfzy.controller.permission;

import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.mapper.permission.CompanyMapper;
import com.hualan.sfzy.model.entity.Points;
import com.hualan.sfzy.service.impl.permission.CompanyServiceImpl;
import com.hualan.sfzy.service.impl.permission.PointsServiceImpl;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/points")
public class PointsController {
    @Autowired
    private PointsServiceImpl service;
    @GetMapping
    public Result find() {
        return Result.success(service.find());
    }
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id) {
        return Result.success(service.findById(id));
    }
    @GetMapping("/page")
    public Result findPage(@RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
                           @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
                           Points points) {
        return Result.success(service.findPage(pageNum, pageSize,
                points));

    }
    @PostMapping
    public Result add(@RequestBody Points points) {
        return service.add(points) > 0 ? Result.success() : Result.error();
    }

    /**
     * 用户积分不应该删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Integer id) {

        return Result.error("用户积分不应该删除");
    }

    @DeleteMapping
    public Result removeBatch(Integer[] ids) {

        return service.removeBatch(ids) > 0 ?Result.success() :Result.error();
    }

    @PutMapping
    public Result edit(@RequestBody Points points) {
        return service.edit(points) > 0 ? Result.success() : Result.error();
    }

}
